package com.neusoft.training.podcast.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.neusoft.training.podcast.entity.User;
import com.neusoft.training.podcast.mapper.UserMapper;
import com.neusoft.training.podcast.service.UserService;

@Service
public class UserServiceImpl implements UserService {

	@Autowired
	private UserMapper userMapper;

	@Override
	public void insert(User user) {
		user.setHeader("/podcast/header/default.jpg");
		userMapper.insert(user);		
	}

	@Override
	public void cleanUser(String name) {
		userMapper.cleanUser(name);		
	}

	@Override
	public void deleteUser(String name) {
		userMapper.deleteUser(name);
	}

	@Override
	public List<User> findAll() {
		return userMapper.findAll();
	}

	@Override
	public User checkNameExist(String name) {
		return userMapper.findByName(name);
	}

	public List<User> findUserByName(String name) {
		return userMapper.findUserByName(name);

	}

	@Override
	public User findUserByID(Integer userID) {
		return userMapper.findUserByID(userID);
	}

	@Override
	public void update(String originalName, String updateName, String updatePwd) {
		userMapper.update(originalName, updateName, updatePwd);
	}

	@Override
	public void register(User user) {
		
		userMapper.insert(user);
	}

	@Override
	public User login(String email, String pwd) {
		
		User result = null;
		User user = userMapper.findByEmail(email);
		
		if(user != null && user.getPwd().equals(pwd))
		{
			result = user;
		}
		
		return result;
	}

	@Override
	public User checkEmailExist(String email) {
		
		return userMapper.findByEmail(email);
	}

	@Override
	public User findByName(String name) {
		
		return userMapper.findByName(name);
	}

	@Override
	public User findByID(Integer userID) {
		
		return userMapper.findUserByID(userID);
	}

	@Override
	public void uploadHeader(String header, Integer userID) {
		
		userMapper.updateUserHeader(header, userID);
		
	}
	@Override
	public User modifyUserInfo(String Oldname,String NewName,String password,String phoneNum,String email) {
	
		
		userMapper.updateAll(Oldname, NewName, password,phoneNum, email);
		
		User user=null;
		user=userMapper.findByName(NewName);
		return user;
	}

	@Override
	public List<User> findVideoUser(Integer userID) {
	    List<User> user =userMapper.findFavouriteAuthor(userID);
		// TODO Auto-generated method stub
		return user;
	}

	@Override
	public List<User> findCommentUser(Integer userID) {
		// TODO Auto-generated method stub
		return userMapper.findCommentUser(userID);
	}

	@Override
	public List<User> findOtheruser(Integer userID) {
		// TODO Auto-generated method stub
		List<User> user= userMapper.findOtherUser(userID);
		System.out.println("其他用户"+user.size());
		return userMapper.findOtherUser(userID);
	}

	@Override
	public List<User> findCommentVideoUser(Integer userID) {
		// TODO Auto-generated method stub
		return userMapper.findCommentVideoUser(userID);
	}
	
}